wxapp.logic.pay = {
    createOrder: function(e, t, r, o) {
        var a = {};
        a.prodId = e, a.prodPrice = t, a.chargeType = "wxapp.iap", a.gameId = tywx.SystemInfo.gameId, 
        a.prodName = r, a.prodCount = o, a.appInfo = {}, wxapp.logic.pay.rechargeOrder(a);
    },
    rechargeOrder: function(e) {
        if (tywx.IsWechatPlatform()) {
            var t = tywx.Util.getLocalUUID(), r = tywx.SystemInfo.loginUrl + "open/v4/pay/order", o = {
                userId: tywx.UserInfo.userId,
                appId: tywx.SystemInfo.appId,
                wxAppId: tywx.SystemInfo.wxAppId,
                clientId: tywx.SystemInfo.clientId,
                imei: "null",
                uuid: t,
                prodId: e.prodId,
                prodName: e.prodName,
                prodCount: e.prodCount || 1,
                prodPrice: e.prodPrice,
                chargeType: e.chargeType,
                gameId: e.gameId,
                appInfo: e.appInfo,
                mustcharge: e.mustcharge || 1
            };
            wx.request({
                url: r,
                header: {
                    "content-type": "application/x-www-form-urlencoded"
                },
                data: o,
                method: "POST",
                success: function(e) {
                    e.data.result.code;
                    var t = e.data.result;
                    if (0 == t.code) {
                        var r = t.chargeInfo, o = r.chargeData, a = o.notifyUrl, n = o.platformOrderId;
                        if (o && 1 == o.mustcharge) {
                            var p = {
                                mode: o.mode,
                                env: o.env,
                                offerId: o.offerId,
                                buyQuantity: 10 * r.chargeTotal,
                                platform: o.platform,
                                currencyType: "CNY",
                                zoneId: o.zoneId,
                                success: function(e) {
                                    wxapp.logic.pay.orderCallFunc(a, n, r.chargeCoin);
                                },
                                fail: function(e) {
                                    e.errCode && 1 == e.errCode && wxapp.logic.pay.cancelOrder(n);
                                }
                            };
                            try {
                                wx.requestMidasPayment(p);
                            } catch (e) {}
                        } else o && 0 == o.mustcharge && wxapp.logic.pay.orderCallFunc(a, n, r.chargeCoin);
                    } else 1 == t.code || t.code;
                },
                fail: function(e) {},
                complete: function(e) {}
            });
        }
    },
    cancelOrder: function(e) {
        var t = tywx.SystemInfo.loginUrl + "open/v4/pay/cancelorder", r = {
            platformOrderId: e,
            appId: tywx.SystemInfo.appId,
            userId: tywx.UserInfo.userId,
            clientId: tywx.SystemInfo.clientId,
            payType: "wxapp.iap"
        };
        wx.request({
            url: t,
            header: {
                "content-type": "application/x-www-form-urlencoded"
            },
            data: r,
            method: "POST",
            success: function(e) {},
            fail: function(e) {},
            complete: function(e) {}
        });
    },
    orderCallFunc: function(e, t, r) {
        if (tywx.IsWechatPlatform()) {
            var o = tywx.Util.getLocalUUID(), a = {
                userId: tywx.UserInfo.userId,
                appId: tywx.SystemInfo.appId,
                wxAppId: tywx.SystemInfo.wxAppId,
                clientId: tywx.SystemInfo.clientId,
                imei: "null",
                uuid: o,
                platformOrderId: t
            };
            wxapp.internalNeetworrk && "https" == e.substr(0, 5) && (e = "http" + e.substr(5)), 
            wx.request({
                url: e,
                header: {
                    "content-type": "application/x-www-form-urlencoded"
                },
                data: a,
                method: "POST",
                success: function(e) {
                    ty && ty.NotificationCenter && ty.NotificationCenter.trigger(hall.EventType.UPDATE_PAY_DIAMOND_SUCCESS, {});
                },
                fail: function(e) {},
                complete: function(e) {}
            });
        }
    }
};